<template>
  <div>
    轮播图组件
    <swiper :options="swiperOption" ref="bannerSwiper" v-if="list.length > 1">
      <swiper-slide v-for="(item, index) in list" :key="index + 'banner'">
        <img :src="item.imageUrl" />
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
import { findComponentUpward } from '@/utils/assist.js'
export default {
  name: "Banner",
  data() {
    return {
      list: ["子组件数据"],
      swiperOption: {
        loop: true,
        //需要分页器
        pagination: {
          el: ".swiper-pagination",
          clickable: true, //允许分页点击跳转
        },
        // slidesPerView: 3,
        slidesPerView: "auto",
        spaceBetween: 30 //设置slide之间距离(px)
      },
    };
  },


  mounted() {
    const comA = findComponentUpward(this, 'Home');  //直接拿到了父组件的实例，而非通过事件通知。
    comA.sayHello();

    // this.getData();

  },
  methods: {
    // async getData() {
    //   let res = await this.$api.getBanner();
    //   this.list = res.banners;
    // }
  },
};
</script>

<style lang="scss" scoped>

.container {
  width: 1350px;
  .swiper-slide {
    max-width: 430px;
    img {
      height: auto;
      max-width: 100%;
    }
  }
}
</style>